package net.jlibrary.curbparking.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.BatchSize;

import net.jlibrary.common.core.annotation.CodeGenComment;
import net.jlibrary.common.core.annotation.Compositor;
import net.jlibrary.common.core.annotation.OperationType;
import net.jlibrary.common.core.annotation.RecordOperation;
import net.jlibrary.common.core.annotation.SearchCondition;
import net.jlibrary.common.core.annotation.SearchField;
import net.jlibrary.common.core.annotation.SeePurview;
import net.jlibrary.common.core.entity.BaseObject;
import net.jlibrary.group.domain.ParkingPlace;

/**
 * 路内停车设备
 * 
 * @author fzys
 *
 */
@Entity(name = "tab_device")
@SeePurview(value = "parkingPlace.globalPath")
@BatchSize(size = 15)
@Compositor
@CodeGenComment(value = "设备管理", genSelect = false)
@RecordOperation(type = { OperationType.UPDATE })
public class Device extends BaseObject {
	private static final long serialVersionUID = -3875856161403191642L;
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@SearchField(value = "id", condition = SearchCondition.EQUAL)
	private Long id;
	@Column(length = 50, unique = true)
	@CodeGenComment(value = "设备编号", viewText = true, viewList = true, required = true)
	@SearchField(value = "code", condition = SearchCondition.EQUAL)
	private String code;// 设备编号
	@Column(length = 50)
	@CodeGenComment(value = "设备名称", viewList = true, required = true)
	private String name;
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "parkingPlace_id")
	@CodeGenComment(value = "停车区", viewList = true, required = true)
	@SearchField(value = "parkingPlace", condition = SearchCondition.EQUAL)
	private ParkingPlace parkingPlace;// 停车区
	@CodeGenComment(value = "经度", viewList = true, required = true)
	private double longitude;// 经度
	@CodeGenComment(value = "维度", viewList = true, required = true)
	private double latitude;// 维度
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "status_id")
	@CodeGenComment(value = "设备状态", viewList = true, required = true)
	@RecordOperation
	private DeviceStatus status;// 设备状态
	@Temporal(TemporalType.TIMESTAMP)
	@CodeGenComment(value = "状态更新时间", viewList = true)
	private Date statusUpTime;
	@Column(length = 200)
	@CodeGenComment(value = "异常原因")
	private String exceptionCause;// 异常原因

	@Column(updatable = false)
	@Temporal(TemporalType.TIMESTAMP)
	@CodeGenComment(value = "创建时间", viewList = true)
	private Date createdate;
	@Temporal(TemporalType.TIMESTAMP)
	private Date lastdate;

	public Long getId() {
		return id;
	}

	@Override
	public Serializable getPrimaryKey() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public ParkingPlace getParkingPlace() {
		return parkingPlace;
	}

	public void setParkingPlace(ParkingPlace parkingPlace) {
		this.parkingPlace = parkingPlace;
	}

	public double getLongitude() {
		return longitude;
	}

	public void setLongitude(double longitude) {
		this.longitude = longitude;
	}

	public double getLatitude() {
		return latitude;
	}

	public void setLatitude(double latitude) {
		this.latitude = latitude;
	}

	public DeviceStatus getStatus() {
		return status;
	}

	public void setStatus(DeviceStatus status) {
		this.status = status;
	}

	public Date getStatusUpTime() {
		return statusUpTime;
	}

	public void setStatusUpTime(Date statusUpTime) {
		this.statusUpTime = statusUpTime;
	}

	public String getExceptionCause() {
		return exceptionCause;
	}

	public void setExceptionCause(String exceptionCause) {
		this.exceptionCause = exceptionCause;
	}

	public Date getCreatedate() {
		return createdate;
	}

	public void setCreatedate(Date createdate) {
		this.createdate = createdate;
	}

	public Date getLastdate() {
		return lastdate;
	}

	public void setLastdate(Date lastdate) {
		this.lastdate = lastdate;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Device other = (Device) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
}
